package com.jfire.codejson.methodinfo.impl.write.extra;

import java.lang.reflect.Method;
import com.jfire.codejson.methodinfo.impl.write.AbstractWriteMethodInfo;
import com.jfire.codejson.util.NameTool;

public class ReturnArrayListMethodInfo extends AbstractWriteMethodInfo
{
    
    public ReturnArrayListMethodInfo(Method method)
    {
        super(method);
        String listName = NameTool.getNameFromMethod(method);
        str = "java.util.ArrayList " + listName + " = " + getValue + ";\n";
        str += "if(" + listName + "!=null)\n{\n";
        str += "\tcache.append(\"\\\"" + listName + "\\\":[\");\n";
        str += "\tint size = " + listName + ".size();\n";
        str += "\tObject valueTmp = null;\n";
        str += "\tfor(int i=0;i<size;i++)\n";
        str += "\t{\n";
        str += "\t\tif((valueTmp=" + listName + ".get(i))!=null)\n";
        str += "\t\t{\n";
        str += "\t\t\tif(valueTmp instanceof String)\n";
        str += "\t\t\t{\n";
        str += "\t\t\t\tcache.append('\\\"').append((String)valueTmp).append('\\\"');\n";
        str += "\t\t\t}\n";
        str += "\t\t\telse\n";
        str += "\t\t\t{\n";
        str += "\t\t\t\tWriterContext.write(valueTmp,cache);\n";
        str += "\t\t\t}\n";
        str += "\t\t\tcache.append(',');\n";
        str += "\t\t}\n";
        str += "\t}\n";
        str += "\tif(cache.isCommaLast()){cache.deleteLast();}\n";
        str += "\tcache.append(\"],\");\n";
        str += "}\n";
    }
    
}
